import React from "react";
import { Component } from "react";
import { getYesterdayStatisticApi, getYesterdayStatisticByEduIdApi } from "../../js/bigscreen/api";
import { withRouter } from "react-router";
import '../../css/bigscreen/statisticanalysis.css'
import { StatisticBox } from "./statisticbox.jsx";





class StatisticAnalysis extends Component {
    constructor(props) {
        super(props);
        this.state = {
            patrolNum: 0,
            inspectNum: 0,
            dangerNum: 0,
            isLoaded: false
        };
    }

    componentDidMount() {
        let educationId = parseInt(sessionStorage.getItem("departmentId"));
        if(this.props.match.params.county != undefined) {
            this.getYesterdayStatisticByEduId(this.props.match.params.county);
        }else {
            this.getYesterdayStatisticByEduId(educationId);
        }
    }
    getYesterdayStatistic = () => {
        getYesterdayStatisticApi().then((res) => {
            if (res.data) {
                this.setState({
                    patrolNum: res.data.patrolnum,
                    inspectNum: res.data.inspectnum,
                    dangerNum: res.data.dangernum,
                    isLoaded: true
                })
            }
        }).catch((e) => {
            console.log(e);
        })
    }

    getYesterdayStatisticByEduId = (parent) => {
        getYesterdayStatisticByEduIdApi(parent).then((res) => {
            if (res.data) {
                this.setState({
                    patrolNum: res.data.patrolnum,
                    inspectNum: res.data.inspectnum,
                    dangerNum: res.data.dangernum,
                    isLoaded: true
                })
            }
        }).catch((e) => {
            console.log(e)
        })
    }




    render() {
        return (
            <div className="statisticBorder">
                <div className="statisticheader">
                    <span className="statisticheadertxt">{this.props.name}</span>
                </div>
                <StatisticBox name="昨日巡更" number={this.state.patrolNum}></StatisticBox>
                <div className="arrow"></div>
                <StatisticBox name="昨日巡检" number={this.state.inspectNum}></StatisticBox>
                <div className="arrow"></div>
                <StatisticBox name="昨日隐患" number={this.state.dangerNum}></StatisticBox>
            </div>

        )
    }
}

export default withRouter(StatisticAnalysis)